import axios from 'axios'
import { ChannelActionType, RootThunkAction } from '..'

export const getChannels = (): RootThunkAction => {
  // 发异步请求
  return async (dispatch) => {
    const res = await axios.get('http://geek.itheima.net/v1_0/channels')
    console.log(res)
    dispatch({
      type: 'channel/SET_CHANNELS',
      initState: res.data.data.channels
    })
  }
}
export const setChannelIndex = (idx: number) : ChannelActionType => {
  return {
    type: 'channel/SET_CHANNEL_INDEX',
    payload: idx
  }
}
